﻿using NUnit.Framework;

namespace Birkelund.QueryStrings.Test
{
    [TestFixture(typeof(DesEncryptionImpl))]
    public class ISymmetricEncryptionTest<TProvider> where TProvider : ISymmetricEncryption, new()
    {
        [TestCase("<|~¨^this IS_a?strange@tæxt++&'%_>")]
        [TestCase("   ")]
        [TestCase("say\r\n\thi")]
        [TestCase("¿¥½ð")]
        [TestCase(null)]
        [TestCase("")]
        [TestCase("æøåÆØÅ")]
        [TestCase(@"\æ &""?øå'%++´`=¨_~^ø.´`|Óʘʤﭿ")]
        [TestCase("thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_thisisalongstring_")]
        public void DefaultEncryptionAndDecryption(string clearText)
        {
            ISymmetricEncryption encryptor = new TProvider();
            string encrypted = encryptor.Encrypt(clearText);
            string decrypted = encryptor.Decrypt(encrypted);

            Assert.AreEqual(clearText, decrypted, "The start and end are not equal");

            if (!string.IsNullOrEmpty(clearText))
            {
                Assert.AreNotEqual(clearText, encrypted, "No transformation has taken place");
            }
        }
    }
}
